import subprocess
# ctrl + /: 注释快捷键
# 1. subprocess.run(列表): 无法识别环境变量
# subprocess.run(   ["ls"]   )  # ls
# subprocess.run(["ls", "/home"])  # ls /home
# subprocess.run(["echo", "$HOME"])  # echo $HOME
# 2. subprocess.run(字符串, shell=True)
# subprocess.run("echo $HOME", shell=True)


# 3. subprocess.run 返回值
result = subprocess.run("ls /home", shell=True)
print("result:", result)
print(result.args, result.returncode)
# result: CompletedProcess(args='ls /home', returncode=0)
# args: run运行的指令
# returncode: 如果为0，表示run运行的指令执行成功;非0,run运行的指令执行失败
result = subprocess.run("id hahaha", shell=True)
print("result:", result)
# result: CompletedProcess(args='id hahaha', returncode=1)
